Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@material/base

Package Overview
Dependencies
Maintainers
13
Versions
1667
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@material/base

The set of base classes for Material Components for the web

  • 0.40.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
885K
decreased by-13.18%
Maintainers
13
Weekly downloads
 
Created

What is @material/base?

@material/base is a foundational package for building Material Design components. It provides base classes and utilities that help in creating custom components that adhere to Material Design guidelines.

What are @material/base's main functionalities?

Foundation Class

The Foundation class is a base class for creating the logic of a Material Design component. It provides a structure for defining the component's behavior and lifecycle methods.

const { MDCFoundation } = require('@material/base');

class MyComponentFoundation extends MDCFoundation {
  constructor(adapter) {
    super(Object.assign(MyComponentFoundation.defaultAdapter, adapter));
  }

  static get defaultAdapter() {
    return {
      addClass: () => {},
      removeClass: () => {},
      // other adapter methods
    };
  }

  // Foundation methods
  init() {
    // Initialization logic
  }

  destroy() {
    // Cleanup logic
  }
}

module.exports = MyComponentFoundation;

Adapter Pattern

The Adapter pattern is used to abstract the DOM manipulation and other platform-specific operations. This allows the foundation logic to be platform-agnostic and reusable.

const { MDCFoundation } = require('@material/base');

class MyComponentAdapter {
  addClass(className) {
    // Add class to the component
  }

  removeClass(className) {
    // Remove class from the component
  }

  // Other adapter methods
}

class MyComponentFoundation extends MDCFoundation {
  constructor(adapter) {
    super(Object.assign(MyComponentFoundation.defaultAdapter, adapter));
  }

  static get defaultAdapter() {
    return {
      addClass: () => {},
      removeClass: () => {},
      // other adapter methods
    };
  }
}

module.exports = { MyComponentAdapter, MyComponentFoundation };

Component Initialization

The Component class is used to initialize and manage the lifecycle of a Material Design component. It ties together the foundation and adapter to create a fully functional component.

const { MDCComponent } = require('@material/base');
const MyComponentFoundation = require('./my-component-foundation');

class MyComponent extends MDCComponent {
  static attachTo(root) {
    return new MyComponent(root, new MyComponentFoundation());
  }

  getDefaultFoundation() {
    return new MyComponentFoundation({
      addClass: (className) => this.root_.classList.add(className),
      removeClass: (className) => this.root_.classList.remove(className),
      // other adapter methods
    });
  }
}

module.exports = MyComponent;

Other packages similar to @material/base

FAQs

Package last updated on 08 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc